//
//  BQTabBarController.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/22.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class BQTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义tabbar
        let tabBar:BQTabBar = BQTabBar()
        
        tabBar.colure = {
            
            print("接受赚钱指令")
            let composeV:ComposeView = ComposeView()
            
            let window:UIWindow = UIApplication.shared.windows.last!
            
            window.addSubview(composeV)
        }
        
        setValue(tabBar, forKey: "tabBar")
       
        
        addChildViewController(vc: HomeController(), title: "首页", imgNamed: "tabbar_home")
        
         addChildViewController(vc: MessageController(), title: "消息", imgNamed: "tabbar_message_center")
        
         addChildViewController(vc: DiscoverController(), title: "发现", imgNamed: "tabbar_discover")
        
         addChildViewController(vc: MeController(), title: "我的", imgNamed: "tabbar_profile")
        
        

       
        
    }
    
     /// 添加子控制器方法
     ///
     /// - parameter vc:       控制器
     /// - parameter title:    导航栏和标签栏的文字
     /// - parameter imgNamed: tabbaritem的图片
     func addChildViewController(vc:UIViewController,title:String,imgNamed:String){
        
        vc.title = title
        
        //设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        
        //tabbar_home_selected
        vc.tabBarItem.image = UIImage(named: imgNamed)
        //设置图片原生的颜色
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let nvc:UINavigationController = BQNavController(rootViewController: vc)
        
        self.addChildViewController(nvc)
    }

    

    
}
